//
//  TotalCoinOfRewardedModel.m
//
//  Created by mac  on 2018/11/29
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "TotalCoinOfRewardedModel.h"


NSString *const kTotalCoinOfRewardedModelCoinAccount = @"CoinAccount";
NSString *const kTotalCoinOfRewardedModelTotalCoinUpLimit = @"TotalCoinUpLimit";
NSString *const kTotalCoinOfRewardedModelYesterdayReward = @"YesterdayReward";
NSString *const kTotalCoinOfRewardedModelPrice = @"Price";


@interface TotalCoinOfRewardedModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation TotalCoinOfRewardedModel

@synthesize coinAccount = _coinAccount;
@synthesize totalCoinUpLimit = _totalCoinUpLimit;
@synthesize yesterdayReward = _yesterdayReward;
@synthesize price = _price;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.coinAccount = [[self objectOrNilForKey:kTotalCoinOfRewardedModelCoinAccount fromDictionary:dict] doubleValue];
            self.totalCoinUpLimit = [[self objectOrNilForKey:kTotalCoinOfRewardedModelTotalCoinUpLimit fromDictionary:dict] doubleValue];
            self.yesterdayReward = [[self objectOrNilForKey:kTotalCoinOfRewardedModelYesterdayReward fromDictionary:dict] doubleValue];
            self.price = [[self objectOrNilForKey:kTotalCoinOfRewardedModelPrice fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.coinAccount] forKey:kTotalCoinOfRewardedModelCoinAccount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.totalCoinUpLimit] forKey:kTotalCoinOfRewardedModelTotalCoinUpLimit];
    [mutableDict setValue:[NSNumber numberWithDouble:self.yesterdayReward] forKey:kTotalCoinOfRewardedModelYesterdayReward];
    [mutableDict setValue:[NSNumber numberWithDouble:self.price] forKey:kTotalCoinOfRewardedModelPrice];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.coinAccount = [aDecoder decodeDoubleForKey:kTotalCoinOfRewardedModelCoinAccount];
    self.totalCoinUpLimit = [aDecoder decodeDoubleForKey:kTotalCoinOfRewardedModelTotalCoinUpLimit];
    self.yesterdayReward = [aDecoder decodeDoubleForKey:kTotalCoinOfRewardedModelYesterdayReward];
    self.price = [aDecoder decodeDoubleForKey:kTotalCoinOfRewardedModelPrice];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_coinAccount forKey:kTotalCoinOfRewardedModelCoinAccount];
    [aCoder encodeDouble:_totalCoinUpLimit forKey:kTotalCoinOfRewardedModelTotalCoinUpLimit];
    [aCoder encodeDouble:_yesterdayReward forKey:kTotalCoinOfRewardedModelYesterdayReward];
    [aCoder encodeDouble:_price forKey:kTotalCoinOfRewardedModelPrice];
}

- (id)copyWithZone:(NSZone *)zone
{
    TotalCoinOfRewardedModel *copy = [[TotalCoinOfRewardedModel alloc] init];
    
    if (copy) {

        copy.coinAccount = self.coinAccount;
        copy.totalCoinUpLimit = self.totalCoinUpLimit;
        copy.yesterdayReward = self.yesterdayReward;
        copy.price = self.price;
    }
    
    return copy;
}


@end
